<template>
	<view class="help-container">

		<view class="subsection">
			<view class="item  " @click="changeType('published')" :class="{'active': currentType==='published' }">
				<view class="num">{{myPublishedOrderList.length}}</view>
				<view class="text">我发布的帮单</view>
			</view>
			<view class="item" @click="changeType('recived')" :class="{'active': currentType==='recived' }">
				<view class="num">{{myRecivedOrderList.length}}</view>
				<view class="text">我接的帮单</view>
			</view>


		</view>

		<view class="card-list" v-if="currentType==='published'">
			<view class="order-card" v-for="(item,index) in myPublishedOrderList" :key="index">
				<orderCard :orderInfo="item"></orderCard>
			</view>
			<emptyData v-if="!myPublishedOrderList.length" :tip="'暂无数据'"></emptyData>
		</view>
		<view class="card-list" v-if="currentType==='recived'">
			<view class="order-card" v-for="(item,index) in myRecivedOrderList" :key="index">
				<orderCard :orderInfo="item"></orderCard>
			</view>
			<emptyData v-if="!myRecivedOrderList.length" :tip="'暂无数据'"></emptyData>
		</view>
	</view>
</template>

<script>
	import orderCard from '../../components/orderCard.vue'
	import emptyData from '../../components/emptyData.vue'
	export default {
		components: {
			orderCard,
			emptyData
		},
		data() {
			return {
				currentType: 'published',
				myPublishedOrderList: [],
				myRecivedOrderList: [],
				orderList: []
			};
		},
		onLoad() {
			this.getOrder()
		},
		methods: {
			changeType(type) {
				this.currentType = type
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 100,
				});
			},
			// 获取帮单信息
			getOrder() {
				this.$http('get', 'api/public/order/list', {
					success: (res) => {
						const userInfo = this.$store.getters?.userInfo?.userInfoDetail || null
						this.orderList = res.data

						this.myPublishedOrderList = this.orderList.filter(item =>
							userInfo ? item.uid === userInfo.uid : false
						)
						this.myRecivedOrderList = this.orderList.filter(item =>
							userInfo ? item.did === userInfo.uid : false
						)

					}
				})
			},

		}
	}
</script>

<style lang="scss">
	.help-container {
		height: 100vh;
		padding: 0 15px;
	}



	.subsection {
		box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
		border-radius: 8px;
		background: #fff;
		height: 80px;
		display: flex;
		align-items: center;

		z-index: 2;

		padding: 10px;

		margin: 15px 0;

		.item {
			flex: 1;
			height: 70px;
			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: center;

			&.active {
				background: rgb(255, 255, 255);
				box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.2);
				border-radius: 8px;

				.text {
					font-weight: 700;
				}
			}

			.num {
				font-size: 18px;
				text-align: center;
				font-weight: 700;
			}

			.text {
				text-align: center;
				font-size: 12px;
				color: rgb(51, 51, 51);
				margin-top: 10px;
			}

			&:nth-child(1) {
				.num {
					color: rgb(254, 185, 58);
				}

			}

			&:nth-child(2) {
				.num {
					color: rgb(101, 132, 247);
				}

			}

		}

	}

	.card-list {
		// margin-top: 130px;
		overflow: auto;
		padding-bottom: 20px;

		.order-card:not(:last-child) {
			margin-bottom: 10px;
		}
	}
</style>